package com.example.finalwork.utils

import android.content.Context
import android.content.SharedPreferences

class SharedPreferencesManager(context: Context) {
    private val preferences: SharedPreferences = context.getSharedPreferences("USER_PREF", Context.MODE_PRIVATE)

    fun saveUser(username: String, password: String) {
        val editor = preferences.edit()
        editor.putString("username", username)
        editor.putString("password", password)
        editor.putBoolean("is_logged_in", true)  // 新增登录状态
        editor.apply()
    }

    fun clearUser() {
        val editor = preferences.edit()
        editor.clear()
        editor.apply()
    }

    fun getUser(): Pair<String?, String?> {
        val username = preferences.getString("username", null)
        val password = preferences.getString("password", null)
        return Pair(username, password)
    }

    fun isUserLoggedIn(): Boolean {
        return preferences.getBoolean("is_logged_in", false) // 检查登录状态
    }
}
